@using System.Text.RegularExpressions
@model ZKEACMS.Product.Models.ProductEntity
@{
    Style.Reqiured("product-ecommerce").AtHead();
    Script.Reqiured("product-ecommerce").AtFoot();
    var firstImage = Model.ProductImages.FirstOrDefault(m => m.Status == (int)RecordStatus.Active);
}
@if (Model != null)
{
    <div class="product-detail">
        <div class="page-header">
            <div class="product-ecommerce">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="thumbnail">
                                @if (firstImage != null)
                                {
                                    <img class="stage" src="@Url.Content(firstImage.ImageUrl)" alt="@firstImage.Title" />
                                }
                                else
                                {
                                    <img class="stage" src="@Url.Content(Model.ImageUrl)" alt="@Model.Title" />
                                }
                            </div>
                            <ul class="thumbnails">
                                @if (firstImage != null)
                                {
                                    foreach (var item in Model.ProductImages.Where(m => m.Status == (int)RecordStatus.Active))
                                    {
                                        <li class="@(item==firstImage?"active":"")">
                                            <a href="javascript:" data-src="@Url.Content(item.ImageUrl)">
                                                <img src="@Url.Content(item.ImageUrl)" alt="@item.Title" />
                                            </a>
                                        </li>
                                    }
                                }
                            </ul>
                        </div>
                        <div class="col-sm-6">
                            <h2>@Model.Title</h2>
                            @if (Authorizer.Authorize(ZKEACMS.Product.PermissionKeys.ManageProduct) && Model.ID > 0)
                            {
                                <p>
                                    <a href="@Url.Action("Edit", "Product", new { id = Model.ID,ReturnUrl=ViewContext.HttpContext.Request.Path })">@L("编辑")</a>
                                </p>
                            }
                            @if (Model.Description.IsNotNullAndWhiteSpace())
                            {
                                <p>
                                    <small class="text-muted">
                                        @Model.Description
                                    </small>
                                </p>
                            }
                            @if (Model.Price.HasValue || Model.RebatePrice.HasValue)
                            {
                                <p>
                                    @Html.LabelFor(m => m.Price)
                                    @if (Model.RebatePrice.HasValue)
                                    {
                                        <del class="text-muted"><small>￥</small>@Html.Raw(Regex.Replace((Model.Price ?? 0).ToString("F2"), @"\.(\d+)", "<small>.$1</small>"))</del>
                                        <span class="price"><small>￥</small>@Html.Raw(Regex.Replace((Model.RebatePrice ?? 0).ToString("F2"), @"\.(\d+)", "<small>.$1</small>"))</span>
                                    }
                                    else
                                    {
                                        <span class="price"><small>￥</small>@Html.Raw(Regex.Replace((Model.Price ?? 0).ToString("F2"), @"\.(\d+)", "<small>.$1</small>"))</span>
                                    }
                                </p>
                            }
                            @if (Model.PartNumber.IsNotNullAndWhiteSpace())
                            {
                                <p>
                                    @Html.LabelFor(m => m.PartNumber)
                                    <span class="text-muted">@Model.PartNumber</span>
                                </p>
                            }
                            @if (Model.Color.IsNotNullAndWhiteSpace())
                            {
                                <p>
                                    @Html.LabelFor(m => m.Color)
                                    <span class="text-muted">@Model.Color</span>
                                </p>
                            }
                            @if (Model.Norm.IsNotNullAndWhiteSpace())
                            {
                                <p>
                                    @Html.LabelFor(m => m.Norm)
                                    <span class="text-muted">@Model.Norm</span>
                                </p>
                            }
                            @if (Model.ShelfLife.IsNotNullAndWhiteSpace())
                            {
                                <p>
                                    @Html.LabelFor(m => m.ShelfLife)
                                    <span class="text-muted">@Model.ShelfLife</span>
                                </p>
                            }
                            @if (Model.ProductTags != null && Model.ProductTags.Any(m => m.Selected))
                            {
                                <div class="tag-select">
                                    @foreach (var item in Model.ProductTags.Where(m => m.ParentId == 0))
                                    {
                                        var childTags = Model.ProductTags.Where(m => m.ParentId == item.ID && m.Selected).ToList();
                                        if (childTags.Any())
                                        {
                                            <div class="tag-grop">
                                                <h4>
                                                    @item.Title
                                                </h4>
                                                <div>
                                                    @foreach (var tag in childTags)
                                                    {
                                                        <input type="radio" id="tag-@tag.ID" name="group-@item.ID" value="@tag.Title" />
                                                        <label for="tag-@tag.ID">@tag.Title</label>
                                                    }
                                                </div>
                                            </div>
                                        }
                                    }
                                </div>
                            }
                            @if (Model.Price.HasValue || Model.RebatePrice.HasValue)
                            {
                                <div class="quantity-set">
                                    <a href="javascript:" class="quantity-minus">
                                        <svg viewBox="0 0 16 2">
                                            <path d="M0 0h16v2H0z"></path>
                                        </svg>
                                    </a>
                                    <span class="quantity">1</span>
                                    <a href="javascript:" class="quantity-plus">
                                        <svg viewBox="0 0 16 16">
                                            <path d="M0 7h16v2H0z"></path>
                                            <path d="M7 0h2v16H7z"></path>
                                        </svg>
                                    </a>
                                </div>
                                <p>
                                    <a class="btn btn-flat btn-lg add-to-basket" href="javascript:" data-productid="@Model.ID" data-quantity="1">
                                        <i class="glyphicon glyphicon-shopping-cart"></i> @L("加入购物车")
                                    </a>
                                </p>
                            }
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <div class="panel-body detail clearfix">
            @Html.Raw(Model.ProductContent)
        </div>
    </div>
}
